package com.dj.myapp;

import android.os.Bundle;
import android.widget.TextView;

import com.dj.myapp.annotation.InjectParam;

import java.util.HashMap;

public class SecondActivity extends BaseActivity {

    String preActivity;
    String stringParam;
    int initParam;
    InjectParam injectParam;

    TextView tv1,tv2,tv3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        init();
    }

    private void init() {

        tv1 = (TextView) findViewById(R.id.tv1);
        tv2 = (TextView) findViewById(R.id.tv2);
        tv3 = (TextView) findViewById(R.id.tv3);

        injectData();


    }

    private void injectData() {

        injectParam=new InjectParam()
                .setInjectUriParam(new String[]{"preActivity"})
                .setInject(new String[]{"stringParam","initParam"});

        HashMap<String,Object> data=mService.getData(this.getIntent(),injectParam);
        if(data!=null){
            for (String key : data.keySet()) {
                if(key.equals("preActivity")){
                    preActivity=data.get(key).toString();
                }
                if(key.equals("stringParam")){
                    stringParam=data.get(key).toString();
                }
                if(key.equals("initParam")){
                    initParam= (int) data.get(key);
                }
            }
        }

        tv1.setText("preActivityName: " + preActivity);
        tv2.setText("stringParam: " + stringParam);
        tv3.setText("intParam: " + initParam);
    }
}